package com.ray.controller;

import com.alibaba.fastjson2.JSON;
import com.ray.pojo.User;
import com.ray.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@CrossOrigin
public class JSONController
{
    @Autowired
    private UserServiceImpl userServiceImpl;

    public void setUserServiceImpl(UserServiceImpl userServiceImpl)
    {
        this.userServiceImpl = userServiceImpl;
    }

    @RequestMapping("vue")
    String toVUEpage()
    {
        return "vue.html";
    }

    @RequestMapping("/jsonVUE")
    @ResponseBody
    String getJSONToVue(Model model)
    {

        List<User> allUser = userServiceImpl.getUserList();


        String s = JSON.toJSONString(allUser);
        System.out.println(s);
        model.addAttribute("msg", s);
        return s;
    }
}
